<style lang="scss" rel="stylesheet/scss">
    .publish-index {
        .content {
            padding-top: 45px;
            .textarea {
                border: 1px solid #f5f5f5;
                margin: 0.4rem 0.6rem;
                textarea {
                    font-size: 14px;
                }
            }
            .pop-title {
                line-height: 2.5rem;
                padding: 0 1rem;
                display: flex;
                border-bottom: 1px solid #f5f5f5;
                .pop-title-item {
                    flex:1;
                    text-align: center;
                    &:nth-child(1) {
                        text-align: left;
                    }
                    &:nth-child(3) {
                        text-align: right;
                    }
                }
            }
            .pop-title-tip {
                line-height: 1rem;
                padding: 0.3rem 1rem;
                color: orange;
            }
            .pop-radio-tip {
                float: left;
                color: orange;
            }
        }
        .border-b {
            border: 1px solid #f5f5f5;
        }
        .van-cell--required {
            overflow: hidden;
        }
    }
</style>
<template>
    <div class="publish-index">
        <jheader :title="headTitle"></jheader>
        <div class="content">
            <div class="border-b" v-if="fromType === 3">
                <van-field
                    label="标题"
                    required
                    v-model="data.title"
                    :error-message="errorMsg.title"
                    placeholder="二手交易物品品牌型号等"/>
            </div>
            <p style="padding:10px 8px;font-size:12px;color:#666;line-height:16px;">{{textareapla}}</p>
            <div class="textarea">
                <van-field
                    ref="input"
                    :placeholder="textareapla"
                    required
                    v-model="data.msg"
                    :error-message="errorMsg.msg"
                    type="textarea"
                    class="font-normal-small font-deep-normal"
                    rows="6"
                    autosize>
                </van-field>
            </div>
            <j-img-video-href :showItem="showItem" @getImgsFn="getImgsFn"></j-img-video-href>
            <van-cell-group style="margin-top:0.8rem;">
                <j-choose-area v-if="fromType === 1" @chooseAreaFn="chooseAreaFn"></j-choose-area>
                <van-cell title="价格" required v-if="fromType === 3" is-link :value="inputItem.price" @click="inputDialog(3)"/>
                <van-cell title="分类" required v-if="fromType === 3" is-link :value="infoType.selectTxt" @click="infoType.popShow=true"/>
                <van-cell title="信息类型" required v-if="fromType != 3" is-link :value="infoType.selectTxt" @click="infoType.popShow=true"/>
                <van-popup v-model="infoType.popShow" position="bottom">
                    <van-picker show-toolbar title="信息类型" :columns="infoType.popList" @cancel="infoType.popShow=false" @confirm="selectInfoType" />
                </van-popup>
                <van-cell v-if="fromType === 1" title="信息时长" required is-link :value="infoTime.selectTxt" @click="infoTime.popShow=true"/>
                <van-popup v-model="infoTime.popShow" position="bottom" >
                    <van-picker show-toolbar title="信息时长" :columns="infoTime.popList" @cancel="infoTime.popShow=false" @confirm="selectInfoTime" />
                </van-popup>
                <van-cell title="信息费用" :value="`${infoTime.price}元`"/>
                
            </van-cell-group>
            <van-cell-group>
                <van-cell title="分享费用" is-link :value="shareMoney.selectTxt" @click="shareMoney.popShow=true"/>
                <van-popup v-model="shareMoney.popShow" position="bottom">
                    <p class="pop-title">
                        <span class="font-zhu font-normal pop-title-item" @click="shareMoney.popShow=false">取消</span>
                        <span class="font-c-normal font-big-normal pop-title-item">信息分享</span>
                        <span class="font-zhu font-normal pop-title-item" @click="shareMoney.popShow=false">确定</span>
                    </p>
                    <p class="font-small pop-title-tip">使用信息分享功能，平台自动帮你分享到朋友圈、好友、群里扩散更快，阅读量更高</p>
                    <van-radio-group v-model="shareMoney.radio">
                        <van-cell-group>
                            <van-cell v-for="item in shareMoney.popList" :key="item.id" :title="`${item.number}人分享（${item.price}元）`" clickable @click="selectShareMoney(item)">
                                <p class="pop-radio-tip" v-if="item.give">赠送{{item.five}}人</p>
                                <van-radio :name="item.id"></van-radio>
                            </van-cell>
                            <van-cell title="不使用分享（0元）" clickable @click="selectShareMoneyNo">
                                <van-radio name="0"></van-radio>
                            </van-cell>
                        </van-cell-group>
                    </van-radio-group>
                </van-popup>
                <van-cell title="置顶费用" is-link :value="totopMoney.selectTxt" @click="totopMoney.popShow=true"/>
                <van-popup v-model="totopMoney.popShow" position="bottom">
                    <p class="pop-title">
                        <span class="font-zhu font-normal pop-title-item" @click="totopMoney.popShow=false">取消</span>
                        <span class="font-c-normal font-big-normal pop-title-item">置顶时长</span>
                        <span class="font-zhu font-normal pop-title-item" @click="totopMoney.popShow=false">确定</span>
                    </p>
                    <van-radio-group v-model="totopMoney.radio">
                        <van-cell-group>
                            <van-cell v-for="item in totopMoney.popList" :key="item.id" :title="`${item.name}（${item.price}元）`" clickable @click="selectTotopMoney(item)">
                                <van-radio :name="item.id"></van-radio>
                            </van-cell>
                            <van-cell title="不使用置顶（0元）" clickable @click="selectTotopMoneyNo">
                                <van-radio name="0"></van-radio>
                            </van-cell>
                        </van-cell-group>
                    </van-radio-group>
                </van-popup>
                <van-cell title="费用合计" :value="`${z_money}元`"/>
            </van-cell-group>
            <van-cell-group>
                <van-cell title="发布区域" v-if="fromType != 1" :value="publicAdr"/>
                <van-cell title="联系人" required :value="inputItem.name" @click="inputDialog(1)"/>
                <van-cell title="联系方式" required :value="inputItem.phone" @click="inputDialog(2)"/>
            </van-cell-group>
            <van-dialog
                v-model="inputPop.show"
                show-cancel-button
                :before-close="dialogFn"
                >
                <van-field
                    v-model="inputPop.name"
                    label="联系人"
                    placeholder="请输入联系人"
                    v-if="inputPop.showItem === 1"
                />
                <van-field
                    v-model="inputPop.phone"
                    label="联系方式"
                    placeholder="请输入联系方式"
                    v-if="inputPop.showItem === 2"
                />
                <van-field
                    v-model="inputPop.price"
                    label="价格"
                    placeholder="请输入价格"
                    type="num"
                    v-if="inputPop.showItem === 3"
                />
            </van-dialog>
            <div style="text-align:center;margin:1rem;">
                <van-button
                    type="primary"
                    @click="submit" :disabled="!btncanclick">
                    支付发布
                </van-button>
            </div>
        </div>
    </div>
</template>

<script>
    import jheader from "components/Header"
    import jImgVideoHref from "components/Form/ImgVideoHref"
    import jChooseArea from "components/Form/ChooseArea"
    import validator from 'utils/validator.js'
    import * as toolsUtils from 'utils/toolsUtils'
    import publicService from 'services/publicService'
    import wx from 'weixin-js-sdk'
    export default {
        components: {
            jheader,
            jImgVideoHref,
            jChooseArea,
        },
        
        data () {
            return {
                headTitle: '发布金牌广告',
                fromtypeobj: {
                    'unitary_advert': 1,
                    'local_general': 4,
                    'second_hand': 3
                },
                textareapla: '',
                fromType: 3,
                fromTypeTxt: 'unitary_advert',
                category_id: '', // 本地信息获取分类
                unionid: '',
                key: '',
                member_hxopenid: '',
                showItem:['img','video','href'],
                imgsfile:[],
                publicArea: { //选择区域
                    type: 0
                },
                publicAdr: '西安',
                infoType: { // 选择信息类型
                    popShow: false,
                    popList: [],
                    selectTxt: '选择信息类型',
                    selectId: ''
                },
                infoTime: { // 选择信息时长
                    popShow: false,
                    popList: [],
                    selectTxt: '选择信息时长',
                    selectId: '',
                    price: '0.00'
                },
                shareMoney: { // 分享费用
                    popShow: false,
                    radio:1,
                    popList: [],
                    selectTxt: '使用分享',
                    selectId: '',
                },
                totopMoney: { // 置顶费用
                    popShow: false,
                    radio:1,
                    popList: [],
                    selectTxt: '去置顶',
                    selectId: '',
                },
                z_money: '0.00',
                inputItem: {
                    name:'',
                    phone: '',
                    price: '面议'
                },
                inputPop: {
                    show: false,
                    name:'',
                    phone: '',
                    price: '',
                    showItem: ''
                },
                addrpop: false, // 二手和本地的 区域选择
                countdown: 0,
                data: {
                    msg: ' ',
                    title: ''
                },
                errorMsg: {
                    msg: '',
                    title: ''
                },
                btncanclick: true,
                rules: {
                    msg: [
                        {required: true, message: '请输入要发布的信息'}
                    ],
                    title: [
                        {
                            validator: (rule, value, callback) => {
                                if(this.fromType === 3) {
                                    if(!value) {
                                        callback('请输入标题');
                                    }else {
                                        callback();
                                    }
                                }else {
                                    callback();
                                }
                                // if (!value) {
                                //     callback('请输入手机号码');
                                // } else if (/^[1][0-9]{10}$/.test(value)) {
                                //     callback();
                                // } else {
                                //     callback('请输入正确的手机号码');
                                // }
                            }
                        }
                    ]
                },
            }
        },
        watch: {
            'publicArea.type'(val) {
                this.infoType.selectTxt = '选择信息类型'
                this.infoTime.selectTxt = '选择信息时长'
                this.infoTime.price = '0.00'
                this.infoType.selectId = ''
                this.infoTime.selectId = ''
                this.getInfoTypeData(val)
                this.getInfoTimeData(this.publicArea.type)
                this.getShareData(this.publicArea.type)
                
                this.z_money = 0
            }
        },
        mounted () {
            if(!this.$route.params.unionid || !this.$route.params.fromType) return
            sessionStorage.clear()
            this.unionid = this.$route.params.unionid
            let fromtype = this.$route.params.fromType
            
            if(fromtype.indexOf('$') != -1) {
                this.fromType = this.fromtypeobj[fromtype.split('$')[0]]
                this.fromTypeTxt = fromtype.split('$')[0]
                this.category_id = fromtype.split('$')[1]
            }else {
                this.fromType = this.fromtypeobj[fromtype]
                this.fromTypeTxt = fromtype
            }
            console.log(this.fromType)

            this.getAuthKey()
            this.initWx()
            // 获取定位信息
            publicService.getLocationArea({unionid:this.unionid}).then(res => {
                if(res) {
                    if(this.fromType === 1) {
                        console.log(res)
                        sessionStorage.setItem('areap_id',res.provinceid)
                        sessionStorage.setItem('areac_id',res.cityid)
                        sessionStorage.setItem('areax_id',res.areaid)
                        sessionStorage.setItem('areaAdr',`${res.provincename}#${res.cityname}#${res.areaname}`)
                    }else {
                        this.publicAdr = res.provincename + res.cityname + res.areaname
                    }
                }else {
                    xmview.showAlert('提示','没有定位相关信息')
                }
            })
            if(this.fromType === 1) { // 广告
                this.headTitle = '发布金牌广告'
                this.textareapla = '可将广告推广到全国，或任意省、市、县区三级区域。请输入广告信息的具体内容：如产品服务信息等'
                // 信息类型
                this.getInfoTypeData(this.publicArea.type)
                // 信息时长
                this.getInfoTimeData(this.publicArea.type)
            }
            if(this.fromType === 3) { // 二手
                this.headTitle = '发布二手交易'
                this.textareapla = '请描述一下您的宝贝新旧、形状等信息（300字以内）'
                this.getSecondHandInfoTYpe()
            }
            if(this.fromType === 4) { //本地
                this.headTitle = '发布本地信息'
                this.textareapla = '信息内容：描述一下所提供的服务，发布的信息'
                this.getLocalInfoType()
            }
            // 分享费用
            this.getShareData(this.publicArea.type)
            // 置顶费用
            this.getTotopMoney()
        },
        created() {
            this.validator = validator(this.rules, this.data);
        },
        methods: {
            // 获取key和用户名字 电话 
            getAuthKey() {
                publicService.getAuthKey({unionid:this.unionid}).then(res => {
                    // console.log(res)
                    if(res) {
                        this.key = res.key
                        this.member_hxopenid = res.member_nickname
                        this.inputItem.name = res.member_nickname
                        this.inputItem.phone = res.member_mobile
                        if(this.fromType === 3 || this.fromType === 4) {
                            let category_id = 126
                            if(this.fromType === 4) category_id = this.category_id
                            publicService.initInfoPrice({key:this.key,category_id:category_id}).then(res => {
                                if(res) {
                                    this.infoTime.price = Number(res.price)
                                    this.getZongMoney()
                                }
                            })
                        }
                    }else {
                        xmview.showAlert('提示','没有登陆相关信息')
                    }
                })
            },
            // 获取信息图片
            getImgsFn(val) {
                if(!val.length) return
                this.imgsfile = val
            },
            // 选择发布区域 0全国 1全省 2全市 3全县
            chooseAreaFn(type) {
                this.publicArea.type = type
            },
            // 获取信息类型 广告
            getInfoTypeData(val) {
                let type = val === 0 ? val : 1
                publicService.getAdverType({fromTypeTxt:this.fromTypeTxt, type:type}).then(res => this.infoType.popList = res)
            },
            // 获取二手分类列表
            getSecondHandInfoTYpe() {
                publicService.getSecondType({fromTypeTxt: this.fromTypeTxt}).then(res => this.infoType.popList = res)
            },
            // 获取本地分类
            getLocalInfoType() {
                publicService.getLocalType({fromTypeTxt: this.fromTypeTxt,category_id: this.category_id}).then(res => this.infoType.popList = res)
            },
            // 选择信息类型
            selectInfoType(picker, index) {
                this.infoType.selectTxt = picker.text
                // picker.value 就是所选的id
                this.infoType.selectId = picker.value
                this.infoType.popShow = false

            },
            // 获取时长信息
            getInfoTimeData(val) {
                publicService.getAdverPrice({fromTypeTxt: this.fromTypeTxt, type: val}).then(res => this.infoTime.popList = res)
            },
            // 选择信息时长
            selectInfoTime(picker, index) {
                this.infoTime.selectTxt = picker.text
                this.infoTime.price = picker.price
                // picker.value 就是所选的id
                this.infoTime.selectId = picker.value
                this.infoTime.popShow = false

                this.getZongMoney()
            },
            // 获取分享费用
            getShareData(val) {
                if(this.fromTypeTxt === 'second_hand') {
                    val = 3
                }else if(this.fromTypeTxt === 'local_general') {
                    val = 4
                }else if(this.fromTypeTxt === 'unitary_advert') {
                    if(val === 0) val = 5
                    if(val === 1) val = 6
                    if(val === 2) val = 7
                    if(val === 3) val =8
                }
                publicService.getSharePrice({share_yibi_id: val}).then(res => this.shareMoney.popList = res)
            },
            // 设置分享费用
            selectShareMoney(item) {
                this.shareMoney.radio = item.id
                this.shareMoney.selectTxt = item.price
                this.shareMoney.selectId = item.id

                this.getZongMoney()
            },
            selectShareMoneyNo() {
                this.shareMoney.selectTxt = '0.00'
                this.shareMoney.selectId = ''
                this.getZongMoney()
            },
            // 获取置顶费用
            getTotopMoney() {
                publicService.getTopPrice().then(res => this.totopMoney.popList = res)
            },
            // 设置置顶费用
            selectTotopMoney(item) {
                this.totopMoney.radio = item.id
                this.totopMoney.selectTxt = item.price
                this.totopMoney.selectId = item.id

                this.getZongMoney()
            },
            selectTotopMoneyNo() {
                this.totopMoney.selectTxt = '0.00'
                this.totopMoney.selectId = ''
                this.getZongMoney()
            },
            // 计算费用 
            getZongMoney() {
                let infoPrice = Number(this.infoTime.price)
                let sharePrice = 0
                if(this.shareMoney.selectId) {
                    sharePrice = Number(this.shareMoney.selectTxt)
                }
                let totopPrice = 0
                if(this.totopMoney.selectId) {
                    totopPrice = Number(this.totopMoney.selectTxt)
                }
                this.z_money = toolsUtils.numAdd(toolsUtils.numAdd(infoPrice,sharePrice),totopPrice)
            },
            // 去编辑联系人信息
            inputDialog(type) {
                this.inputPop.showItem = type
                this.inputPop.show = true
                this.inputPop.name = this.inputItem.name
                this.inputPop.phone = this.inputItem.phone
                // this.inputPop.price = this.inputItem.price
            },
            // 联系人弹框 确定按钮 价格
            dialogFn(action, done) {
                if (action === 'confirm') {
                    if(this.inputPop.showItem === 2) {
                        if(!toolsUtils.checkMobile(this.inputPop.phone)) {
                            xmview.showToast('修改失败，请输入正确的手机号')
                        }else {
                            this.inputItem.phone = this.inputPop.phone
                        }
                        setTimeout(done, 100);
                    }else if(this.inputPop.showItem === 1){
                        if(this.inputPop.name.length > 15) {
                            xmview.showToast('不能多于15个字哦')
                        }else {
                            this.inputItem.name = this.inputPop.name
                        }
                        setTimeout(done, 100);
                    }else if(this.inputPop.showItem === 3) {
                        // debugger
                        let price = this.inputPop.price
                        if(price === '价格面议' || price === '面议') {
                            this.inputItem.price = price
                        }else {
                            price = Number(price)
                            if(isNaN(price)) {
                                xmview.showToast('请输入正确的价格')
                            }else {
                                this.inputItem.price = price
                            }
                        }
                        setTimeout(done, 100);
                    }
                } else {
                    done();
                }
            },
            sendMobileCode() {
                this.validate(errors => {
                    if (!errors) {
                        Toast('发送成功');
                        this.countdown = 60;
                        this.countdownSubtract();
                    }
                }, 'mobile')
            },
            countdownSubtract() {
                if (this.countdown > 0) {
                setTimeout(() => {
                    this.countdown -= 1;
                    this.countdownSubtract()
                }, 1000)
                }
            },
            /**
             * 清除验证提示
             * @param attrs
             */
            resetField(attrs) {
                attrs = !attrs ? Object.keys(this.errorMsg) : ( Array.isArray(attrs) ? attrs : [attrs]);
                attrs.forEach(attr => {
                this.errorMsg[attr] = ''
                })
            },
            /**
             * 验证方法
             * @param callback
             * @param data
             */
            validate(callback, data) {
                this.validator.validate((errors, fields) => {
                    this.resetField();
                    if (errors) {
                        fields.forEach(item => {
                        this.errorMsg[item.field] = item.message
                        })
                    }
                    callback && callback(errors, fields)
                }, data);
            },
            // 点击发布支付
            submit() {
                if(this.fromTypeTxt === 'unitary_advert' || this.fromTypeTxt === 'local_general') {
                    if(!this.data.msg) {
                        xmview.showToast('信息内容不能是空')
                        return
                    }
                }else if(this.fromTypeTxt === 'second_hand') {
                    if(!this.data.title) {
                        xmview.showToast('标题不能是空')
                        return
                    }
                    if(!this.data.msg) {
                        xmview.showToast('信息内容不能是空')
                        return
                    }
                }
                // this.validate((errors, fields) => {
                //     if(errors) return
                    if(this.fromTypeTxt === 'unitary_advert') this.publicGG()
                    else if(this.fromTypeTxt === 'second_hand') this.publicSecondHand()
                    else if(this.fromTypeTxt === 'local_general') this.publicLocal()
                // })
            },
            // 广告
            publicGG() {
                let obj = {}
                obj = this.getImgVideoHref(obj)
                // if(!obj.file) return
                obj.area_type = this.publicArea.type === 0 ? 1 : 2 // 发布区域 1全国 2本地
                if(!this.inputItem.name || !this.inputItem.phone) {
                    xmview.showToast('联系人和联系方式不能是空！')
                    return
                }
                obj.relation_men = this.inputItem.name // 联系人姓名
                obj.relation_tel = this.inputItem.phone // 联系人电话
                obj.content = this.data.msg.replace(/\n|\r\n/g,"<br/>")
                if(obj.area_type === 2) { // 省市区id
                    // this.publicArea.type 0全国 1全省 2全市 3全县
                    if(this.publicArea.type === 1) {
                        obj.areap_id = sessionStorage.getItem('areap_id')
                    }else if(this.publicArea.type === 2){
                        obj.areap_id = sessionStorage.getItem('areap_id')
                        obj.areac_id = sessionStorage.getItem('areac_id')
                    }else if(this.publicArea.type === 3){
                        obj.areap_id = sessionStorage.getItem('areap_id')
                        obj.areac_id = sessionStorage.getItem('areac_id')
                        obj.areax_id = sessionStorage.getItem('areax_id')
                    }
                }
                if(!this.infoType.selectId) {
                    xmview.showToast('请选择信息类型')
                    return
                }
                obj.type_id = this.infoType.selectId
                obj.type = this.infoType.selectTxt // 信息类型
                if(!this.infoTime.selectId) {
                    xmview.showToast('请选择信息时长')
                    return
                }
                obj.rates_id = this.infoTime.selectId // 信息资费
                obj.is_use_privilege = 0 // 是否使用特权默认0 是1
                obj.yibi_spec_id = this.shareMoney.selectId
                obj.top_price_id = this.totopMoney.selectId
                obj.key = this.key
                obj.fromTypeTxt = this.fromTypeTxt

                this.btncanclick = false
                publicService.publicAdver(obj).then(res => this.myPay(res)) 
            },
            // 二手
            publicSecondHand() {
                let obj = {}
                obj = this.getImgVideoHref(obj)
                obj.title = this.data.title
                obj.content = this.data.msg.replace(/\n|\r\n/g,"<br/>")
                if(!this.infoType.selectId) {
                    xmview.showToast('请选择分类')
                    return
                }
                obj.cate_id = this.infoType.selectId // 类别id
                if(this.inputItem.price === '价格面议' || this.inputItem.price === '面议'){
                    obj.price = '0'
                }else {
                    obj.price = this.inputItem.price
                }
                if(!this.inputItem.name || !this.inputItem.phone) {
                    xmview.showToast('联系人和联系方式不能是空！')
                    return
                }
                obj.relation_name = this.inputItem.name // 联系人姓名
                obj.relation_phone = this.inputItem.phone // 联系人电话
                obj.areap_id = sessionStorage.getItem('areap_id')
                obj.areac_id = sessionStorage.getItem('areac_id')
                obj.areax_id = sessionStorage.getItem('areax_id')
                obj.yibi_spec_id = this.shareMoney.selectId
                obj.top_price_id = this.totopMoney.selectId
                obj.key = this.key

                obj.fromTypeTxt = this.fromTypeTxt

                this.btncanclick = false
                publicService.publicSecond(obj).then(res => this.myPay(res))
            },
            // 本地
            publicLocal() {
                let obj = {}
                obj = this.getImgVideoHref(obj)
                obj.content = this.data.msg.replace(/\n|\r\n/g,"<br/>")
                if(!this.infoType.selectId) {
                    xmview.showToast('请选择分类')
                    return
                }
                obj.title = this.infoType.selectTxt
                obj.category_id = this.category_id
                obj.type_id = this.infoType.selectId // 类别id
                if(!this.inputItem.name || !this.inputItem.phone) {
                    xmview.showToast('联系人和联系方式不能是空！')
                    return
                }
                obj.relation_name = this.inputItem.name // 联系人姓名
                obj.relation_phone = this.inputItem.phone // 联系人电话
                obj.areap_id = sessionStorage.getItem('areap_id')
                obj.areac_id = sessionStorage.getItem('areac_id')
                obj.areax_id = sessionStorage.getItem('areax_id')
                obj.detail_address = this.publicAdr
                obj.yibi_spec_id = this.shareMoney.selectId
                obj.top_price_id = this.totopMoney.selectId
                obj.key = this.key
                obj.member_hxopenid = this.member_hxopenid

                obj.fromTypeTxt = this.fromTypeTxt

                this.btncanclick = false
                publicService.publicLocal(obj).then(res => this.myPay(res))
            },
            // 获取视频图片和链接
            getImgVideoHref(obj) {
                // debugger
                // 添加图片
                // if(this.fromType === 1) { // 广告必填
                //     if(!this.imgsfile.length) {
                //         xmview.showToast('请至少添加一个图片')
                //         return obj
                //     }
                // }
                if(this.imgsfile.length) {
                    // debugger
                    let imgsfile = this.imgsfile
                    if(imgsfile.length === 1) {
                        obj.file = imgsfile[0].serverId
                    }else {
                        let file = ''
                        for(let item of imgsfile) {
                            file = file + item.serverId + '|'
                        }
                        obj.file = file
                    }
                    // alert(obj.file)
                    console.log(obj.file)
                }
                // 添加视频
                if(sessionStorage.getItem('video_content')) obj.video_content = sessionStorage.getItem('video_content')
                if(sessionStorage.getItem('video_thumb')) obj.video_thumb = sessionStorage.getItem('video_thumb') 
                // 添加链接
                if(sessionStorage.getItem('linkobj')) {
                    let linkobj = JSON.parse(sessionStorage.getItem('linkobj')) 
                    obj.link_content = linkobj.link_content
                    obj.link_img = linkobj.link_img
                    obj.link_text = linkobj.link_text
                }
                return obj
            },
            myPay(info) {
                this.btncanclick = true
                if(!info) return
                let infos = info
                let obj = JSON.parse(decodeURIComponent(info)) 
                if(Number(obj.actualPrice) == 0) {
                    xmview.showToast('发布成功')
                    if(sessionStorage.getItem('nextpage')) {
                        window.location.href = sessionStorage.getItem('nextpage')
                    }
                    return
                }
                let params = {
                    info:infos,
                    pdc_sn:obj.pdc_sn,
                    actualPrice:obj.actualPrice,
                    key: this.key,
                    wx: 'xc'
                }
                publicService.toWxPay(params).then(res => this.wxPay(res))
                
            },
            wxPay(data) {
                // debugger
                wx.chooseWXPay({
                    timestamp: data.timestamp, // 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
                    nonceStr: data.noncestr, // 支付签名随机串，不长于 32 位
                    package: `prepay_id=${data.prepayid}`, // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=\*\*\*）
                    signType: 'MD5', // 签名方式，默认为'SHA1'，使用新版支付需传入'MD5'
                    paySign: data.sign, // 支付签名
                    success: function (res) {
                        // 支付成功后的回调函数
                        xmview.showToast('支付成功')
                        if(sessionStorage.getItem('nextpage')) {
                            window.location.href = sessionStorage.getItem('nextpage')
                        }else {
                            xmview.showToast('没有nextpage')
                        }
                    }
                })
            },
            // 初始化jssdk 用于微信支付
            initWx() {
                let url = window.location.href.split('#')[0]
                // alert(url)
                publicService.initWxConfig({url:url}).then(res => {
                    // alert(res.appId)
                    //wx是引入的微信sdk
                    wx.config({
                        debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                        appId: res.appId, // 必填，公众号的唯一标识
                        timestamp: res.timestamp, // 必填，生成签名的时间戳
                        nonceStr: res.nonceStr, // 必填，生成签名的随机串
                        signature: res.signature,// 必填，签名
                        jsApiList: ['chooseWXPay','chooseImage', 'uploadImage', 'getLocalImgData', 'onMenuShareAppMessage','onMenuShareTimeline'] // 必填，需要使用的JS接口列表
                    });

                    let _this = this
                    wx.ready(function () {   //需在用户可能点击分享按钮前就先调用
                        // 朋友
                        wx.onMenuShareAppMessage({
                            title: '营销精准高效，推广传播更快，人人转发赚钱的平台', // 分享标题
                            desc: '发布金牌广告，营销精准高效！全国地区自由选择，人人分享，专业推广', // 分享描述
                            link: `${xmconfig.Index_url}`, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                            imgUrl: 'https://wechat.yjsb18.com/img/share/share_money.png', // 分享图标
                            success: function () {
                            // 用户点击了分享后执行的回调函数
                            }
                        });
                        // 朋友圈
                        wx.onMenuShareTimeline({
                            title: '营销精准高效，推广传播更快，人人转发赚钱的平台', // 分享标题
                            link: `${xmconfig.Index_url}`, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                            imgUrl: 'https://wechat.yjsb18.com/img/share/share_money.png', // 分享图标
                            success: function () {
                                // 用户点击了分享后执行的回调函数

                            },
                        })
                    });
                })
            }
                
        }
        
    }
</script>

